/**
 * Created by yuzhou on 2020/3/29.
 */
//获取
$(document).ready(function () {
    var app = new Vue({
        el: "#whole_box",
        data: {
            area_name:"",
            area_map:"",
            shop_no:"",
            main_pro_txt:"",
            bottom1:"市场导购",
            bottom2:"动态资讯",
            bottom3:"联系我们",
            store_list:[],
            is_en:false,
            page_num:1,
            search_txt:""
        },
        mounted:function(){
            var self = this;
            var market = self.getQueryValue("market");
            var name = self.getQueryValue("name");
            var area = self.getQueryValue("area");
            var market_name="";

            var lanuage_type = localStorage.getItem("language");
            if(lanuage_type == "cn"){
                self.shop_no = "店铺号";
                self.main_pro_txt = "主营";
                self.bottom1 = "市场导购";
                self.bottom2 = "动态资讯";
                self.bottom3 = "联系我们";
                self.is_en = false;
                self.search_txt = "搜索更多..";
            }else{
                self.shop_no = "Shop No";
                self.main_pro_txt = "Main Products";
                self.bottom1 = "MarketShopping"+"\n"+"Guide";
                self.bottom2 = "Dynamic"+"\n"+"Information";
                self.bottom3 = "Contact Us";
                self.is_en = true;
                self.search_txt = "Search More..";
            }

            if(market == 1){
                market_name = "广州信基沙溪酒店用品博览城";
            }else if(market == 2){
                market_name = "广州信基豪泰酒店用品城";
            }else if(market == 3){
                market_name = "沈阳信基沙溪酒店用品博览城";
            }

            self.area_name = market_name+name;

            $.ajax({
                type:"GET",
                url:"/market/getAreaPic",
                data: {
                    area:area,
                },
                dataType:"text",
                success:function(res){
                    self.area_map = res;
                }
            });

            $(window).scroll(function () {
                var scrollTop = $(this).scrollTop();
                var scrollHeight = $(document).height();
                var windowHeight = $(this).height();

                if (Math.round(scrollTop + windowHeight) == scrollHeight) {
                    self.page_num = self.page_num+5;
                    self.requestStore(area);
                }
            });

            self.requestStore(area);

        },
        methods: {
            getQueryValue:function (a) {
                var query = decodeURI(window.location.search.substring(1));
                var vars = query.split("&");
                for (var i = 0; i < vars.length; i++) {
                    var pair = vars[i].split("=");
                    if (pair[0] == a) { return pair[1]; }
                }
                return null;
            },

            getback:function () {
                window.history.back(-1);
            },

            requestStore:function (area) {
                var self = this;
                $.ajax({
                    type:"GET",
                    url:"/market/getMarketByArea",
                    data: {
                        area:area,
                        language:localStorage.getItem("language"),
                        page:self.page_num
                    },
                    dataType:"json",
                    success:function(res){
                        if(self.page_num > 1){
                            self.store_list = self.store_list.concat(res);
                        }else{
                            self.store_list = res;
                        }

                    }
                });
            },

            call:function (a) {
                var self = this;
                window.location.href = "tel:"+a;
            },

            storDetail:function (a) {
                window.location.href = "/page/redirectStoreDeatil?id="+a;
            },


        },

    });
});